home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Box / box_private.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  6.1 KB  |  260 lines

  1. /* util.c: file containing public and private utility routines */
  2.  
  3. #include <stdio.h>
  4. #include <X11/Xlib.h>
  5. #include "box_types.h"
  6. #include "box_global.h"
  7.  
  8. ClearBox(gnrc,bx)
  9.  
  10. BoxStatus *gnrc;
  11. BoxList *bx;
  12.  
  13. {
  14.   GC gc;
  15.  
  16.   if(bx->state == BOX_YES)
  17.      gc = gnrc->gc;  /* If bx "on" reverse colors */
  18.   else
  19.      gc = gnrc->reverse_gc;
  20.  
  21.   XFillRectangle(dpy,gnrc->TopWindow,gc,bx->x,bx->y,bx->width,bx->height);
  22. }
  23.  
  24. DrawBox(gnrc,bx)
  25.  
  26. BoxStatus *gnrc;
  27. BoxList *bx;
  28.  
  29. {
  30.   TextList *txt;
  31.   GC gc;
  32.   BoxAttributeList *attr;
  33.   int x,y,width,height;
  34.  
  35.   if(bx == &(gnrc->box)) return(0);
  36.   if(bx->visible == BOX_NO && bx->always_visible == BOX_NO) return(0);
  37.  
  38.   x = bx->x; y = bx->y;
  39.   if(bx->state == BOX_YES) {
  40.      XFillRectangle(dpy,gnrc->TopWindow,gnrc->gc,x,y,
  41.                 bx->width,bx->height);
  42.     }
  43.   else {
  44.      XFillRectangle(dpy,gnrc->TopWindow,gnrc->reverse_gc,x,y,
  45.                 bx->width,bx->height);
  46.     }
  47.  
  48.   if(bx->border) {   /* Draw borders */
  49.      XDrawRectangle(dpy,gnrc->TopWindow,gnrc->gc,x,y,
  50.                                                  bx->width,bx->height);
  51.     }
  52.   txt = bx->txt.next;
  53.   while(txt != NULL) {
  54.      attr = txt->attr;
  55.      if(bx->state == BOX_YES) gc = attr->reverse_gc;
  56.      else gc = attr->gc;
  57.      BoxDrawText(gnrc,bx,txt,gc);
  58.      txt = txt->next;
  59.     }
  60.  
  61.   /* Type specific drawing */
  62.   switch(bx->type) {
  63.      case BOX_TEXT_ENTRY:
  64.        txt = &(bx->prompt); attr = txt->attr;
  65.        if(bx->state == BOX_YES) gc = attr->reverse_gc;
  66.        else gc = attr->gc;
  67.        BoxDrawText(gnrc,bx,txt,gc);
  68.  
  69.        txt = &(bx->dflt); attr = txt->attr;
  70.        if(bx->state == BOX_YES) gc = attr->reverse_gc;
  71.        else gc = attr->gc;
  72.        BoxDrawText(gnrc,bx,txt,gc);
  73.  
  74.        if(bx->state == BOX_YES) {
  75.           /* place cursor */
  76.           x = bx->x + BOX_PAD + bx->dflt.x + 
  77.                XTextWidth(attr->fontstruct,txt->text,strlen(txt->text));
  78.           y = bx->y + bx->dflt.y - attr->fth;
  79.           XDrawLine(dpy,gnrc->TopWindow,gc,x,y,x,y+attr->fth);
  80.          }
  81.        break;
  82.  
  83.       case BOX_HORIZONTAL_SLIDER:
  84.         x = bx->x; y = bx->y;
  85.         height = bx->height; width = (int) (bx->value * (double) bx->width);
  86.         XFillRectangle(dpy,gnrc->TopWindow,gnrc->gc,x,y,width,height);
  87.         break;
  88.  
  89.       case BOX_VERTICAL_SLIDER:
  90.         width = bx->width; height = (int) (bx->value * (double) bx->height);
  91.         x = bx->x; y = bx->y + bx->height - height;
  92.         XFillRectangle(dpy,gnrc->TopWindow,gnrc->gc,x,y,width,height);
  93.         break;
  94.     }
  95. }
  96.  
  97. BoxDrawText(gnrc,bx,txt,gc)
  98.  
  99. BoxStatus *gnrc; BoxList *bx;
  100. TextList *txt; GC gc;
  101. {
  102.   XDrawString(dpy,gnrc->TopWindow,gc,bx->x + txt->x,bx->y + txt->y,
  103.                  txt->text,strlen(txt->text));
  104. }
  105.  
  106.  
  107. BoxList *FindBoxByPosition(gnrc,x,y)
  108.  
  109. BoxStatus *gnrc;
  110. int x,y;
  111.  
  112. /*********** Check box lists for hits: a hit occurs if (x,y) is in box, 
  113.   box->type != BOX_FOR_SHOW, and box->visible = BOX_YES.
  114.   And: BoxIsValidChoice(gnrc,bx) returns 1 *****************/
  115.  
  116. {
  117.   BoxList *bx,*rtrn;
  118.   int generation;
  119.   
  120.   bx = gnrc->box.next;
  121.   rtrn = &(gnrc->box);
  122.   generation = -1;
  123.  
  124.   while(bx != NULL) {
  125.  
  126.      if(x >= bx->x && x <= bx->x + bx->width && y >= bx->y &&
  127.         y <= bx->y + bx->height && bx->type != BOX_FOR_SHOW &&
  128.         (bx->visible == BOX_YES || bx->always_visible == BOX_YES)) {
  129.  
  130.          if(BoxIsValidChoice(gnrc,bx)) {
  131.             if(bx->parent == gnrc->current_box) { rtrn = bx; break; }
  132.             if(bx->generation > generation) {
  133.                generation = bx->generation;
  134.                rtrn = bx;
  135.               }
  136.            }
  137.         }
  138.      bx = bx->next;
  139.     }
  140.   return(rtrn);
  141. }
  142.  
  143. BoxList *FindBoxByID(gnrc,id)
  144.  
  145. BoxStatus *gnrc;
  146. int id;
  147.  
  148. {
  149.  
  150.   BoxList *bx;
  151.   
  152.   bx = &(gnrc->box);
  153.   while(bx != NULL && bx->id != id) {
  154.      bx = bx->next;
  155.     }
  156.   return(bx);
  157. }
  158.  
  159. PrintBoxInfo(fp,gnrc,bx)
  160.  
  161. FILE *fp;
  162. BoxStatus *gnrc;
  163. BoxList *bx;
  164.  
  165. {
  166.   double x_mm,y_mm,width_mm,height_mm;
  167.   TextList *txt;
  168.  
  169.   if(bx == &(gnrc->box)) {
  170.     fprintf(fp,"Top Level box.\n");
  171.     return(0);
  172.    }
  173.  
  174.   x_mm = (double) bx->x /xppmm;
  175.   y_mm = (double) bx->y /yppmm;
  176.   width_mm = (double) bx->width/xppmm;
  177.   height_mm = (double) bx->height/yppmm;
  178.   fprintf(fp,"Box %d\n",bx->id);
  179.   fprintf(fp,"  type %d\n",bx->type);
  180.   fprintf(fp,"  position  %.2lf %.2lf\n",x_mm,y_mm);
  181.   fprintf(fp,"  size  %.2lf %.2lf\n",width_mm,height_mm);
  182.   if(bx->key != '\0')
  183.        fprintf(fp,"  key %c\n",bx->key);
  184.   fprintf(fp,"End\n");
  185.  
  186.   /* Text */
  187.   txt = bx->txt.next;
  188.   while(txt != NULL && txt->text[0] != '\0') {
  189.      x_mm = (double) (txt->x) / xppmm; y_mm = (double) (txt->y) / yppmm;
  190.      fprintf(fp,"Text %d %.2lf %.2lf \"%s\" %d\n",bx->id,x_mm,y_mm,
  191.                                             txt->text,txt->attr->id);
  192.      txt = txt->next;
  193.     }
  194.   if(bx->parent != &(gnrc->box))
  195.      fprintf(fp,"Child %d %d\n",bx->id,bx->parent->id);
  196.  
  197.   /* Flags */
  198.   if(bx->exclusive == BOX_YES) fprintf(fp,"Exclusive %d\n",bx->id);
  199.   if(bx->always_visible == BOX_YES)
  200.      fprintf(fp,"AlwaysVisible %d\n",bx->id);
  201.  
  202.   /* Type specific info */
  203.   switch(bx->type) {
  204.      case BOX_TEXT_ENTRY:
  205.        txt = &(bx->prompt);
  206.        if(txt->text[0] != '\0') {
  207.           fprintf(fp,"Prompt %d \"%s\" %d\n",bx->id,txt->text,txt->attr->id);
  208.          }
  209.        txt = &(bx->dflt);
  210.        if(txt->text[0] != '\0') {
  211.           fprintf(fp,"Default %d \"%s\" %d\n",bx->id,txt->text,txt->attr->id);
  212.          }
  213.        break;
  214.  
  215.      case BOX_HORIZONTAL_SLIDER:
  216.      case BOX_VERTICAL_SLIDER:
  217.        fprintf(fp,"Value %d %.4lf\n",bx->id,bx->value);
  218.        break;
  219.     }
  220.   fprintf(fp,"\n");
  221. }
  222.  
  223. BoxAttributeList *FindBoxAttributeByID(gnrc,id)
  224.  
  225. BoxStatus *gnrc;
  226. int id;
  227.  
  228. {
  229.   BoxAttributeList *attr;
  230.   attr = &(gnrc->attribute);
  231.   while(attr != NULL && attr->id != id) { attr = attr->next; }
  232.   return(attr);
  233. }
  234.  
  235. BoxIsADescendent(gnrc,child,parent)
  236.  
  237. BoxStatus *gnrc;
  238. BoxList *child,*parent;  
  239.  
  240. /* Routine returns 1 if child is a descendent of parent, 0 otherwise */
  241.  
  242. {
  243.   BoxList *bx;
  244.   bx = child;
  245.   while(bx != &(gnrc->box) && bx->parent != parent) bx = bx->parent;
  246.   if(bx == &(gnrc->box)) return(0);
  247.   else return(1);
  248. }
  249.  
  250. BoxIsASibling(gnrc,bx,sibling)
  251.  
  252. BoxStatus *gnrc;
  253. BoxList *bx,*sibling;
  254.  
  255. {
  256.  
  257.   if(bx->parent == sibling->parent) return(1);
  258.   else return(0); 
  259. }
  260.